package cn.semes.system.controller;

import cn.semes.basic.query.BaseQuery;
import cn.semes.basic.util.AjaxResult;

import cn.semes.basic.util.PageList;
import cn.semes.system.domain.Systemdictionarydetail;
import cn.semes.system.domain.Systemdictionarytype;
import cn.semes.system.service.ISystemDetailService;
import cn.semes.system.service.ISystemTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sysdetail")
public class SystemDetailController {

    @Autowired
    private ISystemDetailService service;

    @Autowired
    private ISystemTypeService service1;

    // 分页查
    @PostMapping()
    public PageList<Systemdictionarydetail> queryByPage(@RequestBody BaseQuery query) {
        return service.queryByPage(query);
    }

    @PutMapping()
    public AjaxResult addOrUpdate(@RequestBody Systemdictionarydetail Systemdictionarydetail) {
        if (null != Systemdictionarydetail.getId()) {
            // 修改
            service.update(Systemdictionarydetail);
        } else {
            // 添加
            service.add(Systemdictionarydetail);
        }
        return AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        service.delete(id);
        return AjaxResult.me().success();
    }

    @GetMapping()
    public List<Systemdictionarytype> findAll() {
        return service1.findAll();
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PatchMapping()
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        System.out.println(ids);
        service.batchDelete(ids);
        return AjaxResult.me().success();
    }

    // 抽屉组件
    @GetMapping("/find/{id}")
    public List<Systemdictionarydetail> findByDeptId(@PathVariable("id") Long id) {
        return service.findByDeptId(id);
    }

}
